﻿Imports System.Xml

Namespace Stories
	Public Class Note
		Inherits Child

		Public Sub New()
			Me.Children = New List(Of Child)
		End Sub

		Public Property Collapsed As Boolean?

		Public Property CreationDate As DateTime?

		Public Property ModificationDate As DateTime?

		Public Property UserName As String

		Public Property AppliedDocumentUser As String

		Public Property Children As List(Of Child)

		Public Shared Function ReadNote(reader As XmlReader) As Note
			Dim n As New Note()

			n.Collapsed = Parser.ParseBoolean(reader.GetAttribute("Collapsed"))
			n.CreationDate = Parser.ParseDate(reader.GetAttribute("CreationDate"))
			n.ModificationDate = Parser.ParseDate(reader.GetAttribute("ModificationDate"))
			n.UserName = reader.GetAttribute("UserName")
			n.AppliedDocumentUser = reader.GetAttribute("AppliedDocumentUser")

			While reader.Read()
				Select Case reader.Name
					Case "Footnote"
						n.Children.Add(Footnote.ReadXml(reader))
					Case "GaijiOwnedItemObject"
						n.Children.Add(GaijiOwnedItemObject.ReadXml(reader))
					Case "TextVariableInstance"
						n.Children.Add(TextVariableInstance.ReadXml(reader))
					Case "Table"
						n.Children.Add(Table.ReadXml(reader))
					Case "ParagraphStyleRange"
						n.Children.Add(ParagraphStyleRange.ReadXml(reader))
					Case "CharacterStyleRange"
						n.Children.Add(CharacterStyleRange.ReadXml(reader))
					Case "HiddenText"
						n.Children.Add(HiddenText.ReadXml(reader))
					Case "Note"
						If reader.NodeType = XmlNodeType.EndElement Then Exit While
					Case Else
						Debug.WriteLine("Unrecognized element: {0} in element: {1}", reader.Name, "Note")
				End Select
			End While

			Return n
		End Function
	End Class
End Namespace